<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Programming Constructs</title>
</head>

<body>
    <SCRIPT>
        // if 结构
        var count = 5;
        var money = 0;
        var unitPrice = 80;
        if (count == 1) {
            money = unitPrice * count * 0.8;
        } else if (count == 2) {
            money = unitPrice * count * 0.7;
        } else {
            money = unitPrice * count * 0.5;
        }
        console.log(money);
        // switch 结构
        switch (count) {
            case 1:
                money = unitPrice * count * 0.8;
                break;
            case 2:
                money = unitPrice * count * 0.7;
                break;
            default:
                money = unitPrice * count * 0.5;
                break;
        }
        console.log(money);

        // while 循环
        var i = 0;
        var sum = 0;
        while (i < 10) {
            sum += i; //sum = sum + i;
            i++;
        }
        console.log(sum);

        // do while 循环
        var j = 0;
        var sum2 = 0;
        do {
            sum2 += j;
            j++;
        } while (j < 10)
        console.log(sum2);

        // for 循环
        var k = 0;
        var sum3 = 0;
        for (k = 0; k < 10; k++) {
            sum3 += k;
        }
        console.log(sum3);
        // for循环 遍历数组
        var arr = new Array(3);
        arr[0] = "Jack";
        arr[1] = "Tom";
        arr[2] = "Steve";
        // arr.length 表示数组arr的长度；在本例子中，arr.length=3
        for (var m = 0; m < arr.length; m++) {
            var name = arr[m];
            console.log(name);
        }

        // continue 跳过当前循环，继续执行后续的循环
        var p = 0;
        var sum4 = 0;
        for (p = 0; p < 10; p++) {
            if (p % 2 == 0) {
                continue;
            }
            sum4 += p;
        }
        console.log(sum4);

        // break 退出循环
        var h = 0;
        var sum5 = 0;
        for (h = 0; h < 10; h++) {
            if (h == 3) {
                break;
            }
            sum5 += h;
        }
        console.log(sum5);
    </SCRIPT>
</body>

</html>